package com.bodu;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class M {

    public static void main(String[] args) throws IOException {
        String url = "https://www.boc.cn/sourcedb/whpj/";
        Connection connect = Jsoup.connect(url);

        Document document = connect.get();

        Elements elements = document.body().select("div table tr");
//        货币名称	现汇买入价	现钞买入价	现汇卖出价	现钞卖出价	中行折算价	发布日期	发布时间
        StringBuffer s = new StringBuffer("");
        for (Element e : elements) {
            StringBuffer sb = new StringBuffer();
            e.select("td").forEach(ew -> {
                sb.append(ew.text()).append(",");
            });
            
            s.append(sb.toString()).append("\n");
        }
        System.out.println(s.toString());
//        System.out.println(document.body().text());
    }
    
}
